package io.gitee.icefairy.total_monitor.handler

import cn.hutool.db.Db
import io.gitee.icefairy.total_monitor.repo.ItemRepo
import kotlinx.coroutines.selects.select
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import xyz.erupt.annotation.`fun`.AutoCompleteHandler

/**
 * AUTHOR:icefairy
 * DATE:2021/12/23 0023 11:56
 **/
@Component
class AutoCompleteHandler :AutoCompleteHandler {
    @Autowired
    lateinit var db :Db
    override fun completeHandler(`val`: String?, param: Array<out String>?): MutableList<Any> {
        val typ=param?.firstOrNull()?:"0"
        var sql=""
        if (typ.contentEquals("0")){
            sql="select distinct group_set name from z_item"
        }else if (typ.contentEquals("1")){
            sql="select distinct project name from z_item"
        }
        return db.query(sql).map { it.getStr("name") }.toMutableList()
    }
}